package com.java46.admin.dessert.service;

import com.java46.admin.base.exception.BusinessException;
import com.java46.admin.dessert.dao.AdminDessertDao;
import com.java46.admin.dessert.entity.DessertAndDessertType;
import com.java46.admin.dessert.util.Page;
import com.java46.front.dessert.entity.DessertEntity;
import com.java46.front.dessert.service.DessertService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.List;

public class AdminDessertService extends DessertService {

    AdminDessertDao dao = new AdminDessertDao();

    public Page query_Dessert_All(int pageNO,int pageSize,String condition){
        Page page = new Page();
        //得到商品总数
        int allRow = dao.query_Dessert_getSize(condition);
        //开始记录当前页数
        int offset = page.countOffset(pageNO,pageSize);
        //得到分页查询结果集
        List<DessertAndDessertType> dessertAndDessertTypeList = dao.query_Dessert_All(pageNO,pageSize,condition);
        page.setPageNo(pageNO);
        page.setPageSize(pageSize);
        page.setTotalRecords(allRow);
        page.setList(dessertAndDessertTypeList);
        return page;
    }

    /**
     * 删除商品
     */
    public void delete_Dessert(String dessertId){
        int Id = Integer.parseInt(dessertId);
        dao.delete_Dessert(Id);
    }

    /**
     * 添加商品
     */
    public void add_Dessert(DessertEntity dessertEntity){
        if (dessertEntity==null){
            throw new BusinessException("商品对象不能为空...");
        }
        dao.add_Dessert(dessertEntity);
    }
    //根据商品编号查询商品
    public DessertEntity getDessertByDessertId(String dessertId){
        if(dessertId==null||"".equals(dessertId)){
            throw new BusinessException("请传入商品Id");
        }
        int id =Integer.parseInt(dessertId);
        return dao.getDessertByDessertId(id);
    }
    //修改商品
    public void update_dessert(DessertEntity dessertEntity){
        dao.update_dessert(dessertEntity);
    }
}
